package com.yupi.mybi.scheduled;

import com.yupi.mybi.context.BaseContext;
import com.yupi.mybi.model.entity.Chart;
import com.yupi.mybi.service.ChartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
@Slf4j
public class ChartTask {

    @Autowired
    private ChartService chartService;

    @Scheduled(cron = "0 * * * * ?")//每分钟触发一次
    public void processTimeOutOrder(){
        log.info("处理无法生成的图表:{}", LocalDateTime.now());

        LocalDateTime time = LocalDateTime.now().plusMinutes(-5);
        List<Chart> charts = chartService.getStatusAndFailed();
        if(charts != null || charts.size() > 0){
            Chart chart = new Chart();
            chart.setId(BaseContext.getCurrentId());
            chart.setStatus("Failed");
            chart.setGenChart("服务器异常,生成失败");
            chartService.updateById(chart);
        }
    }
}
